package com.demo.server.init;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import com.demo.server.config.mqtt.MqttCallbackCustom;
import com.demo.server.config.mqtt.MqttConfig;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@ConditionalOnBean(MqttConfig.class)
public class MqttInit implements ApplicationRunner,Ordered{
	

	@Autowired
	private MqttClient mqttClient;
	
	@Autowired
	private MqttCallbackCustom callback;
	
	@Override
	public int getOrder() {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public void run(ApplicationArguments args) throws Exception {
		// TODO Auto-generated method stub
		log.info("mqtt初始化>>>>");
		mqttClient.setCallback(callback);
	}

}
